package com.next

// @TypeChecked
// @CompileStatic
class CustomInterceptor
{
    def springSecurityService

    CustomInterceptor()
    {
        matchAll().excludes(uri: '/static/images/**')
    }

    boolean before()
    {
        // def username = springSecurityService.getPrincipal().username
        // def user = User.findByUsername(username)
        // Boolean flag = true

        // Boolean flag = false
        // def securityProfileItem = SecurityProfileItem.findByProfileAndControllerNameAndActionName(user?.securityProfile, params['controller'], params['action'])
        // if (securityProfileItem)
        // {
        //     if (securityProfileItem?.active)
        //     {
        //         flag = true
        //     }
        //     else
        //     {
        //         flag = false
        //     }
        // }
        // if (!flag)
        // {
        //     flash.message = "对不起，您没有此项操作权限"
        //     redirect controller: "opportunity", action: "index"
        // }

        // params['currentUsername'] = username

        // flag
        true
    }

    boolean after()
    {
        // def username = springSecurityService?.getPrincipal()?.username
        // def user = User.findByUsername(username)
        // def menus = []
        // if (user?.dynamicMenu)
        // {
        //     def userRoles = UserRole.findAllByUser(user)
        //     userRoles?.each { userRole ->
        //         if (userRole?.role?.menu && userRole?.role?.menu?.items?.size() > 0)
        //         {
        //             def items = MenuItem.findAll("from MenuItem where menu.id = ? order by displayOrder asc", [userRole?.role?.menu?.id])
        //             items?.each { item ->
        //                 if (!item?.parent)
        //                 {
        //                     def firstLevel = [:]
        //                     firstLevel['menu'] = item
        //                     def secondLevels = MenuItem.findAll("from MenuItem where parent.id = ? order by displayOrder asc", [item?.id])
        //                     if (secondLevels?.size() > 0)
        //                     {
        //                         firstLevel['items'] = secondLevels
        //                     }
        //                     menus.add(firstLevel)
        //                 }
        //             }
        //         }
        //     }
        // }
        // if (model)
        // {
        //     model.currentUser = user
        //     model.currentMenus = menus
        // }
        // else
        // {
        //     def model = [:]
        //     model.currentUser = user
        //     model.currentMenus = menus
        // }

        true
    }

    void afterView()
    {
        // no-op
    }
}
